package main

import "fmt"

func main(){
	array := []int{1,5,0,4,7,8,2}
	array =quick_sort(array)
	fmt.Println(array)
}
func quick_sort(arr []int) []int{
	if len(arr) <= 1{
		return arr
	}
	pivot := arr[len(arr) / 2]
	left := make([]int, 0)
	middle := make([]int, 0)
	right := make([]int, 0)
	for _, i := range arr{
		switch {
		case i < pivot:
			left = append(left, i)
		case i == pivot:
			middle = append(middle, i)
		case i > pivot:
			right = append(right, i)
		}
	}
	res := append(quick_sort(left),middle...)
	res = append(res,quick_sort(right)...)
	return res
}


